var db=require("../db/db.js");
var express=require("express");
var router=require('vue-router')
var app=express();
var bodyParser=require("body-parser");
const { request, response } = require("express");
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
var router=express.Router();

db.Comment.find().then(res=>{
    console.log(res)
})
router.get("/comments",(request,response)=>{

    // new db.Comment(request.query).save().then(()=>{
    // db.Comment.find({index:request.query.index}).then(res=>{

    new db.Comment(request.query).save()
    
    db.Comment.find({index:request.query.index}).then(res=>{
        if(res!=''){
            console.log(res)

            response.send(res)
        }
        
    })
    
})
router.get("/comments/render",(request,response)=>{
    db.Comment.find().then(res=>{
        if(res!=""){
            response.send(res)
        }
    
    })
})
router.get("/comments/delete",(request,response)=>{
    db.Comment.deleteOne({_id:request.query._id}).then(()=>{
        db.Comment.find().then(res=>{
            if(res!=""){
                response.send(res)
            }
        })
    })
})
module.exports=router;